<?php
if(!isset($_SESSION['userid']))
{
header("location:portal.php");
}
// αν έχει γίνει η καταχώρηση εμφανίζεται το αντίστοιχο μήνυμα, αλλιώς εμφανίζεται η φόρμα καταχώρησης
if ($_GET['adRegistration'] == "success") 
{
	echo 'Your ad was added';
} 
else if($_GET['adRregistration'] == "failed") 
{
	echo 'Error: Your ad was not added';
}
else
{
?>
<br><br><br>
<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
<script language="javascript">
	function check_validation()
	{
		// validation for username
		if(document.getElementById("ad_title").value.split(" ").join("") == "")
		{
			alert("Please enter advertisement title.");
			document.getElementById("ad_title").focus();
			//jQuery("#user_name_error_value").html("Please enter username.");
			//jQuery("#user_name_error").fadeIn("slow");
			return false;
		}
		else
		{
			//jQuery("#user_name_error").fadeOut("slow");
		}
		
		// validation for users first name
		if(document.getElementById("ad_desc").value.split(" ").join("") == "")
		{
			alert("Please enter your advertisement description.");
			document.getElementById("ad_desc").focus();
			//jQuery("#user_fname_error_value").html("Please enter your first name.");
			//jQuery("#user_fname_error").fadeIn("slow");
			return false;
		}
		
		// validation for users last name
		if(document.getElementById("ad_code").value.split(" ").join("") == "")
		{
			alert("Please enter advertisement code.");
			document.getElementById("ad_code").focus();
			//jQuery("#user_lname_error_value").html("Please enter your surname.");
			//jQuery("#user_lname_error").fadeIn("slow");
			return false;
		}
		
		//http://www.w3resource.com/javascript/form/phone-no-validation.php
		// validation for users primary phone number
		if(document.getElementById("ad_type").value.split(" ").join("") == "")
		{
			alert("Please enter position type.");
			document.getElementById("ad_type").focus();
			//jQuery("#user_phone1_error_value").html("Please enter your primary phone number.");
			//jQuery("#user_phone1_error").fadeIn("slow");
			return false;
		}
		
		
		if(document.getElementById("ad_email").value.split(" ").join("") == "")
			{
				alert("Please enter advertisement email address.");
				//alert('Please enter your email address.'); 
				document.getElementById("ad_email").focus();
				//jQuery("#user_email_error_value").html("Please enter your location.");
				//jQuery("#user_email_error").fadeIn("slow");
				return false;
			}
			else
			{
				var emailPat=/^(.+)@(.+)$/
				var matchArray=document.getElementById("ad_email").value.match(emailPat)
			
				if (matchArray==null) 
				{
					//alert("")
					alert('The email address that you have entered is invalid.'); 
					document.getElementById("ad_email").focus();
					//jQuery("#user_email_error_value").html("The email address that you have entered is invalid.");
					//jQuery("#user_email_error").fadeIn("slow");
					return false;
				}
		}
		
		// validation for users location
		if(document.getElementById("autocomplete").value.split(" ").join("") == "")
		{
			alert("Please enter your location.");
			document.getElementById("autocomplete").focus();
			//jQuery("#autocomplete_error_value").html("Please enter your location.");
			//jQuery("#autocomplete_error").fadeIn("slow");
			return false;
		}
		
		if(document.getElementById("ad_catid").value.split(" ").join("") == "")
		{
			alert("Please enter advertisement category.");
			document.getElementById("ad_catid").focus();
			//jQuery("#user_website_error_value").html("The email address that you have entered is invalid.");
			//jQuery("#user_website_error").fadeIn("slow");
			return false;
		}
		
		if(document.getElementById("ad_salary").value.split(" ").join("") == "")
		{
			alert("Please enter indicative salary.");
			document.getElementById("ad_salary").focus();
			//jQuery("#user_website_error_value").html("The email address that you have entered is invalid.");
			//jQuery("#user_website_error").fadeIn("slow");
			return false;
		}
		
		return true;
	}
	function check_validation_of_field($value_of_field,$type_of_field)
	{
		if($value_of_field != "")
		{
			$.post( "http://192.185.116.17/~wwwmsc/includes/check_validation.php?field_type="+$type_of_field+"&field_value="+$value_of_field, function( data ) {
				if($type_of_field == "user_name")
				{
					if(data == "no_conflict")
					{
						jQuery("#user_name_error").fadeOut("slow");
					}
					else
					{
						jQuery("#user_name_error_value").html("The username that you have entered already exists, Please enter different username.");
						jQuery("#user_name_error").fadeIn("slow");
					}
				}
				else if($type_of_field == "user_email")
				{
					if(data == "no_conflict")
					{
						jQuery("#user_email_error").fadeOut("slow");
					}
					else
					{
						jQuery("#user_email_error_value").html("The email that you have entered already exists, Please enter different email.");
						jQuery("#user_email_error").fadeIn("slow");
					}
				}
			});
		}
	}
</script>
Εισαγωγή Αγγελιας
<form name="AdsRegistrationForm" action="includes/AdsRegister.php" method="POST" onsubmit="javascript:return check_validation();">
	<table width="100%" border="0">
    	<tr>
        	<td width="100%" align="right">Τίτλος Θέσης:</td>
            <td width="100%" align="left"><input type="text" id="ad_title" name="ad_title"  size="30"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Περιγραφή:</td>
            <td width="100%" align="left"><textarea  id="ad_desc" name="ad_desc" style="width:44%;" rows="3"></textarea></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Κωδικός Θέσης:</td>
            <td width="100%" align="left"><input type="text" id="ad_code" name="ad_code"  size="30"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Τύπος Θέσης:</td>
            <td width="100%" align="left"><input type="text" id="ad_type" name="ad_type"  size="30"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Email:</td>
            <td width="100%" align="left"><input type="text" id="ad_email" name="ad_email"  size="30"></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Address:</td>
            <td width="100%" align="left">
                <div id="locationField">
                  <input id="autocomplete" placeholder="Εισάγετε τη διεύθυνση σας"
                         onFocus="geolocate()" type="text" name="autocomplete" style="width:44%;"></input>
                </div>
            
                <table id="address" hidden="true">
                  <tr>
                    <td class="label">Διεύθυνση</td>
                    <td class="slimField"><input class="field" id="street_number" name="street_number" disabled="true"></input></td>
                    <td class="wideField" colspan="2"><input class="field" id="route" name="route" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Πόλη</td>
                    <td class="wideField" colspan="3"><input class="field" id="locality" name="locality" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Νομός</td>
                    <td class="slimField"><input class="field" id="administrative_area_level_1" name="administrative_area_level_1" disabled="true"></input></td>
                    <td class="label">Τ.Κ.</td>
                    <td class="wideField"><input class="field" id="postal_code" name="postal_code" disabled="true"></input></td>
                  </tr>
                  <tr>
                    <td class="label">Country</td>
                    <td class="wideField" colspan="3"><input class="field"
                          id="country" disabled="true"></input></td>
                  </tr>
                </table>
            </td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Κατηγορία:</td>
            <td width="100%" align="left">
             <select name="ad_catid" id="ad_catid"> 
                            <option value="">Επιλέξτε Κατηγορία </option>
                            <?php $select_cat="select * from CATEGORIES ";
                            $cat_result=mysql_query($select_cat);
                            while($cat_row=mysql_fetch_array($cat_result))
                            {
                            ?><option value="<?php echo $cat_row['cat_id'];?>" ><?php echo $cat_row['cat_desc'];?></option><?
                            
                            }
                            
                            ?></select>
            <!--input type="text" id="ad_catid" name="ad_catid"  size="30">--></td>
        </tr>
    	<tr>
        	<td width="100%" align="right">Ενδεικτικός Μίσθος:</td>
            <td width="100%" align="left"><input type="text" id="ad_salary" name="ad_salary"  size="30"></td>
        </tr> 
    	<tr>
        	<td width="100%" align="right">&nbsp;</td>
            <td width="100%" align="left"><input type="Submit"  value="Καταχώρηση"></td>
        </tr> 
    </table>
</form>
<?php
}
?>
